package joney.main;

import joney.model.DataModel;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

	public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
		super(configurer);
	}

	public ActionBarAdvisor createActionBarAdvisor(
			IActionBarConfigurer configurer) {
		return new ApplicationActionBarAdvisor(configurer);
	}

	public boolean preWindowShellClose() {

		if(DataModel.isDirty && MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
				, "Save", "Changes have occured\nDo you want to save?"))
		{
			if(DataModel.saveDefaultFile())
			{
				MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), null, 
						"Saved " + DataModel.DEFAULT_FILE_PATH);
			}
		}
		
		return true;
	}
	
	public void preWindowOpen() {
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
		configurer.setInitialSize(new Point(1372, 752));
		configurer.setShowCoolBar(false);
		configurer.setShowStatusLine(false);
		//configurer.setShowPerspectiveBar(true);
	}
}
